define(function () {
    'use strict';
    function ctrl($scope,$state, LocalCacheService,$ionicLoading, DeviceService, CommonService,WebService) {
        var userInfo = LocalCacheService.getUser();
        function init() {
            $scope.user = {
                name: userInfo.client_name
            }
        }

        $scope.$on('$ionicView.beforeEnter', function () {
            init()
        });

        $scope.video = function () {
            //视频验证成功返回
            var params = {
                user_id: userInfo.user_id,
                client_name:userInfo.client_name,
                branch_no:userInfo.branch_no,
                businessNumber: '4'
            };


            DeviceService.asyncVideo(params, function (data) {
                $ionicLoading.show();
                if (data.error_no == 0) {
                    WebService.qryUserInfo().then(
                        function (result) {
                            $ionicLoading.hide();
                            LocalCacheService.setUser(result);
                            CommonService.showComplete('../view/template/videotemplate.html', '返回', 'tab.account-manager');
                        }, function(result){
                            $ionicLoading.hide();
                            CommonService.showAlert({message: result.error_info});
                        });
                } else if (data.error_no == 2) {
                    $ionicLoading.hide();
                    $state.go('tab.account-changeid');
                } else {
                    $ionicLoading.hide();
                    if (data.errorInfo) {
                        CommonService.showAlert({message: data.errorInfo});
                    }
                }
            })

        }
    }

    ctrl.$inject = ['$scope', '$state', 'LocalCacheService','$ionicLoading',  'DeviceService', 'CommonService','WebService'];
    return ctrl;
});